#include "pch.hpp"
#include "WindowHook.hpp"
#include "WindowHookHelper.hpp"

#include <boostext/smart_ptr.hpp>




extern boostext::smart_ptr<WindowHookHelper> m_windowHook;




WindowHook::WindowHook(const WindowProc& windowProc, HWND window)
	: m_windowProc(windowProc)
	, m_window(window)
{
	if(!m_windowHook)
		m_windowHook = boostext::smart_ptr<WindowHookHelper>(new WindowHookHelper());

	// Add ourselves to the list of dispatchers
	m_windowHook->registerHook(this);
}
///////////////////////////////////////////////////////////////////////////////////////////////////

WindowHook::~WindowHook()
{
	// Remove ourselves from the list of dispatchers
	m_windowHook->unregisterHook(this);

	if(!m_windowHook->numHooks())
		m_windowHook.release();
}
///////////////////////////////////////////////////////////////////////////////////////////////////




HWND WindowHook::window() const
{
	return m_window;
}
///////////////////////////////////////////////////////////////////////////////////////////////////

void WindowHook::windowProc(int message, WPARAM wParam, LPARAM lParam) const
{
	m_windowProc(message, wParam, lParam);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
